<?php
namespace Util\CompaniesToPay;
require_once THINK_PATH . 'Library/Util/CompaniesToPay/TransferCost.Data.php';
require_once THINK_PATH . 'Library/Util/CompaniesToPay/WxPay.Config.php';
require_once THINK_PATH . 'Library/Util/CompaniesToPay/WxPay.Exception.php';
/**
 * Created by PhpStorm.
 * User: mao
 * Date: 2017/3/24
 * Time: 15:43
 */

class init {

    private $openid;
    private $money;
    private $Desc;
    private $Device_info;

    public function Setinit($openid, $money, $Desc='测试', $Device_info='123456789') {
        $this->openid = $openid;
        $this->money = $money;
        $this->Desc = $Desc;
        $this->Device_info = $Device_info;
    }

    public function hanld() {
        $input = new WxPayUnifiedOrder();
        $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
//		设置商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
        $input->SetOut_trade_no(WxPayConfig::MCHID . date("YmdHis"));
        $input->SetTotal_fee($this->money);//资金
        $input->SetOpenid($this->openid);//设置poenid
        $input->SetAppid(WxPayConfig::APPID);//公众账号ID
        $input->SetMch_id(WxPayConfig::MCHID);//商户号
        $input->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
        $input->SetNonce_str($input->getNonceStr());//随机字符串
        $input->SetDesc($this->Desc);//企业付款描述信息
        $input->SetCheck_name(NO_CHECK);//校验用户姓名选项SetRe_user_name
        $input->SetDevice_info($this->Device_info);//设备号
//		$input->SetRe_user_name('黎应社');//真实姓名

        $input->SetSign();//签名
        $xml = $input->ToXml();
        $response = $input->postXmlCurl($xml, $url, true, $timeOut = 30);
        $msg = (array)simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA);
        if ($msg['return_code'] == 'SUCCESS' && !$msg['return_msg']) {
            return true;
        } else {
            return $msg;
        }
    }


}